home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 6.3 KB | 201 lines |
- 'Program : Read mouse registers (all Amiga's)
- 'Carbon14 : Paul Overy
- '
- 'I wrote this program after seeing the sticks extension which was
- 'rather amusingly priced at �10. Sticks allows you to read the
- 'mouse with the multitasking system turned off.
- 'This program does not cover all the Sticks commands can but it should
- 'do all you will ever really neeed to know. As half the commands in
- 'Sticks will only be used by 1% of Amos users.
- '
- 'Hmmm, might have a go at writing an extension, think all call it PDsticks.
- '
- 'Oh yeh, this program also shows you how to draw to just one bitplane
- '
- '(Buy the Turbo Plus Extension for Amos & Amos pro.)
- '(It cuts down on code & speeds up Amos. )
- '(I hate writing code without turbo instructions. )
- '
- Screen Open 0,320,256,4,Lowres : Flash Off : Curs Off : Palette 0,$222,$FFF,$F0F
- Get Sprite 1,0,0 To 16,16
- Centre Border$("Mouse Registers by Paul Overy",1)
- Text 0,30,"Horizontal position counter."
- Text 0,40,"Vertical position counter..."
- Text 0,50,"Left button................."
- Text 0,60,"Right button................"
- Text 0,100,"Left draw plane 1 (does not draw over text)"
- Text 0,110,"Right draw plane 0 (draws only on text)"
- Text 0,140,"Both mouse buttons to quit"
- Text 0,160,"Amos can't do this with the multitasking "
- Text 0,170,"system turned off"
- Text 0,180,"i.e X mouse ="
- Text 0,190," Y mouse = No values returned"
- MX=160 : MY=100
- OLD_MX=MX : OLD_MY=MY
- Doke $DFF036,0 : Rem Reset both mouse counters
- Change Mouse 2
- '
- '*** Turn of multi task system, programs run faster now ***
- NULL=Execall(-132)
- '
- Repeat
- '*** Read mouse regesters ***
- 'Because the pointers are so small extra work now needs to
- 'be carried out on them.
- Y_BYTE=Peek($DFF00A) : Rem like "x mouse" but only values 0-255
- X_BYTE=Peek($DFF00B) : Rem like "y mouse" but only values 0-255
- 'Read mouse buttons
- LEFT_CLICK=(Btst(6,$BFE001)=0)
- RIGHT_CLICK=(Btst(10,$DFF016)=0)
- 'Port 2 mouse, bits 7 & 14 with $dff00c & $dff00d
- '
- '*** display info ***
- Ink 2,1
- Text 168,30,Str$(X_BYTE)-" "+" "
- Text 168,40,Str$(Y_BYTE)-" "+" "
- Text 168,50,Str$(LEFT_CLICK)
- Text 168,60,Str$(RIGHT_CLICK)
- Text 88,180,Str$(X Mouse)
- Text 88,190,Str$(Y Mouse)
- '
- '*** mouse controll system ***
- 'Extra work to convert mouse byte pointers, to screen size.
- DX=X_BYTE-OX : DY=Y_BYTE-OY : OX=X_BYTE : OY=Y_BYTE
- 'check for under/overflow correct with difference
- '2 if's could be used here,ie. Abs(DX)>127 then reseting mouse difference
- 'But this is one of the better methods
- If DX<-127 Then DX=256+DX
- If DX>127 Then DX=DX-256
- If DY<-127 Then DY=256+DY
- If DY>127 Then DY=DY-256
- Add MX,DX : Add MY,DY
- '
- '*** Keep cursor inside screen ***
- 'This cuts down on 4 if's
- MY=Max(Min(MY,255),0)
- MX=Max(Min(MX,319),0)
- '
- ' Move mouse pointer using new Mouse Driver values
- ' X Mouse=X Hard(MX) :rem if you want to move Amos pointer
- ' Y Mouse=Y Hard(MY)
- Sprite 2,X Hard(MX),Y Hard(MY),1
- If LEFT_CLICK
- LINE_ONE_PLANE[OLD_MX,OLD_MY,MX,MY,1]
- Else
- If RIGHT_CLICK
- LINE_ONE_PLANE[OLD_MX,OLD_MY,MX,MY,0]
- Else
- ' Hslider 20,251 To 275,255,256,X_BYTE,0
- ' Vslider 315,0 To 319,255,256,Y_BYTE,0
- End If
- End If
- OLD_MX=MX : OLD_MY=MY : Rem for connecting line
- Until LEFT_CLICK and RIGHT_CLICK
- '
- NULL=Execall(-138)
- '
- '
- Procedure LINE_ONE_PLANE[X1,Y1,X2,Y2,PLANE]
- '
- 'Oh'my whats this?
- 'I think its a ID header for a procedure
- 'Yes thats right..... Come on you people you don't
- 'write a procedure and let people guess the rest.
- '
- '***************************************
- '* Procedure: Draw line on 1 bitplane. *
- '* Bloke: Paul Overy *
- '* Inputs: X1,Y1 = starting points *
- '* X2,Y2 = end points *
- '* PLANE = 0 to 4 *
- '* Outputs: None *
- '* *
- '* NOTE: No error checking is done. *
- '* Make sure a plane is there before *
- '* you wrire to it. *
- '* *
- '* ie. 4col screen has 2 planes *
- '* 8col screen has 3 planes *
- '* 16col screen has 4 planes *
- '* 32col screen has 5 planes *
- '* *
- '* Dont forget planes start at ZERO. *
- '***************************************
- '
- PRE_CALC=Screen Width/8
- PH=Phybase(PLANE)
- XD=X2-X1
- YD=Y2-Y1
- SS=1
- If XD<0
- XD=Abs(XD)
- SS=-SS
- End If
- If YD<0
- YD=Abs(YD)
- SS=-SS
- End If
- If XD>YD
- CC=XD/2
- If X1>X2
- Swap X1,X2
- Swap Y1,Y2
- End If
- YT=Y1
- For XT=X1 To X2
- P=Peek(XT/8+YT*PRE_CALC+PH)
- Bset(7-(XT-(XT/8*8))),P
- Poke(XT/8+YT*PRE_CALC+PH),P
- Add CC,YD
- If CC>XD
- Add YT,SS
- Add CC,-XD
- End If
- Next XT
- Else
- CC=YD/2
- If Y1>Y2
- Swap Y1,Y2
- Swap X1,X2
- End If
- XT=X1
- For YT=Y1 To Y2
- P=Peek(XT/8+YT*PRE_CALC+PH)
- Bset(7-(XT-(XT/8*8))),P
- Poke(XT/8+YT*PRE_CALC+PH),P
- Add CC,XD
- If CC>=YD
- Add XT,SS
- Add CC,-YD
- End If
- Next YT
- End If
- End Proc
- Procedure _PLOT[X,Y,PLANE]
- '
- '***************************************
- '* Procedure: Plot pixel on 1 bitplane *
- '* Bloke: Paul Overy *
- '* Inputs: X,Y = pixel location *
- '* PLANE = 0 to 4 *
- '* Outputs: None *
- '* *
- '* NOTE: No error checking is done. *
- '* Make sure a plane is there before *
- '* you wrire to it. *
- '* *
- '* ie. 4col screen has 2 planes *
- '* 8col screen has 3 planes *
- '* 16col screen has 4 planes *
- '* 32col screen has 5 planes *
- '* *
- '* Dont forget planes start at ZERO. *
- '***************************************
- '
- PRE_CALC=Screen Width/8
- PH=Phybase(PLANE)
- XC=X/8
- P=Peek(XC+Y*PRE_CALC+PH)
- Bset(7-(X-(XC*8))),P
- Poke(XC+Y*PRE_CALC+PH),P
- End Proc